//
//  MNDTransferRecordViewController.m
//  minidai
//
//  Created by 谭谭伟 on 17/5/21.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDTransferRecordViewController.h"
#import "MNDTransferRecordCell.h"
#import "MNDTransferRecordModel.h"
@interface MNDTransferRecordViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *topTipLabel;
@property (nonatomic,strong) NSMutableArray *transferArrayM;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMarginConstraint;

@end

@implementation MNDTransferRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.tableView.tableFooterView = [[UIView alloc]init];
    // Do any additional setup after loading the view.
    self.tableView.estimatedRowHeight = 40;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (kDevice_iPad) {
        self.bottomMarginConstraint.constant = 114;
    }else {
        if (kScreenWidth > 375) {
            self.bottomMarginConstraint.constant = 114;
        }else {
            self.bottomMarginConstraint.constant = 50;
        }

    }
}

- (NSMutableArray *)transferArrayM {
    if (!_transferArrayM) {
        _transferArrayM = [NSMutableArray array];
    }
    return _transferArrayM;
}

-(void)setTransfer:(NSArray *)transfer {
    _transfer = transfer;
    //债权记录
//    NSArray *transferArray = transfer.allValues;
    for (NSDictionary *dict in transfer) {
        MNDTransferRecordModel *transferRecordModel = [MNDTransferRecordModel yy_modelWithDictionary:dict];
        [self.transferArrayM addObject:transferRecordModel];
    }
   
    if (self.transferArrayM.count <= 0) {
        [self creatMaskView];
    }
    [self.tableView reloadData];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.transferArrayM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MNDTransferRecordModel *model = self.transferArrayM[indexPath.row];
    MNDTransferRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MNDTransferRecordCell"];
    cell.userNameLabel.text = model.user_name;
    cell.tenderUserNameLabel.text = model.tender_user_name;
    cell.timeLabel.text = model.time;
    cell.principalLabel.text = model.principal;
    return cell;
}

- (void)creatMaskView {
    UIView *maskView = [[UIView alloc]initWithFrame:self.view.bounds];
    maskView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
//    [self.view insertSubview:maskView aboveSubview:self.tableView];
    [self.tableView addSubview:maskView];
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"financen_detail_data_empty"]];
    [maskView addSubview:imgV];
    imgV.layer.cornerRadius = imgV.bounds.size.height*0.5;
    imgV.clipsToBounds = YES;
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(maskView);
        make.centerY.equalTo(maskView).mas_offset(-80);
    }];
//    self.maskView = maskView;
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (kDevice_iPad) {
        return;
    }
    CGFloat distance = scrollView.contentOffset.y;
    if (distance < -10) {
        NSLog(@"------%f------",distance);
        self.topTipLabel.alpha = (-distance-10)/30;
        NSLog(@"------透明度%f------",self.topTipLabel.alpha);
    }
    if (distance == 0) {
        self.topTipLabel.alpha = 0;
    }
    if (distance < -40) {
        self.topTipLabel.text = @"释放回到出借详情";
    }else {
        self.topTipLabel.text = @"下拉回到出借详情";
    }
}

//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
//    if (self.delegate && [self.delegate respondsToSelector:@selector(transferRecordRecordBottomViewDidEndDragging:)]) {
//        
//        [self.delegate transferRecordRecordBottomViewDidEndDragging:self.tableView];
//    }
//}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    if (self.delegate && [self.delegate respondsToSelector:@selector(transferRecordRecordBottomViewDidEndDragging:)]) {
        
        [self.delegate transferRecordRecordBottomViewDidEndDragging:self.tableView];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
